package com.bRoom.common;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class ForgetToken {

    public  static  final  String FORGET_TOKEN="FORGET_TOKEN";


    public  static  final LoadingCache<String,String>  loadingCache= CacheBuilder.newBuilder().maximumSize(1000).initialCapacity(1000).expireAfterAccess(12, TimeUnit.HOURS)
            .build(new CacheLoader<String, String>() {
                @Override
                public String load(String s) throws Exception {
                    return "null";
                }

            });

    public  static  void setKey(String key,String value){
           loadingCache.put(key,value);
    }

    public  static  String getKey(String key){

               String value=null;

        try {
            value=loadingCache.get(key);
            if ("null".equals(value)){
                return null;
            }
            return value;
        } catch (ExecutionException e) {
            e.printStackTrace();
        }


        return null;
    }
}
